package com.distributeredis.redis_springboot.springapachehttpclienthttpconnectionresttemplate.httpclient.study2.controller;

import com.distributeredis.redis_springboot.springapachehttpclienthttpconnectionresttemplate.httpclient.study2.vo.BasicEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("/test")
public class TestController {
    /**
     * get方式请求 有参数
     * @param basicEntity
     * @return
     */
    @GetMapping("/doget")
    public BasicEntity doGet(BasicEntity basicEntity) {
        String age = basicEntity.getSex();
        if(age.equals("男")) {
            basicEntity.setSex("1");
        }else {
            basicEntity.setSex("0");
        }
        return basicEntity;
    }

    /**
     * get方式请求 无参数
     * @param
     * @return
     */
    @GetMapping("/doget1")
    public Object doGet1() {
        return Arrays.asList(new BasicEntity("张三","男"),
                new BasicEntity("李四","女"),
                new BasicEntity("王五","女"));
    }


    /**
     * post方式请求
     * @param basicEntity
     * @return
     */
    @PostMapping("/dopost")
    public BasicEntity dopost(@RequestBody BasicEntity basicEntity) {
        String age = basicEntity.getSex();
        if(age.equals("男")) {
            basicEntity.setSex("1");
        }else {
            basicEntity.setSex("0");
        }
        return basicEntity;
    }
}
